import csv
import idaapi
import idautils
import idc

idaapi.autoWait()

numfunc = sum(1 for _ in Functions())
segs = Segments()
textseg = segs.next()
while SegName(textseg) != '.text':
    textseg = segs.next()

clabel = 'y' if idc.GetInputFile().startswith('bubble') else 'n'
row = [clabel]

for r, d, files in os.walk('./scripts'):
    for script_name in files:
        if not script_name.endswith('.py'):
            continue
        script_path  = os.path.join(r,script_name)
        locals = { 'loc' : textseg, 'ret' : None}
        execfile(script_path, locals)
        row.extend(locals['ret'])

with open("data.csv", 'ab') as f:
    writer = csv.writer(f)
    writer.writerow(row)

idc.Exit(0)